package com.edais.service.imp;

import java.util.List;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.edais.actions.UserRankAction;
import com.edais.dao.UserRankDao;
import com.edais.domain.UserRank;
import com.edais.service.UserRankService;

@Service
public class UserRankServiceImpl implements UserRankService {

	private static final Log logger = LogFactory.getLog(UserRankServiceImpl.class);
	
	@Autowired
	private UserRankDao userRankDao;
	
	@Override
	public List<UserRank> queryUserRankList(String loggerInfo,Map<String, Object> map) throws Exception {
		// TODO Auto-generated method stub
		List<UserRank> resultList=userRankDao.queryUserRankList(map);
		if(resultList!=null){
			for(UserRank userRank:resultList){
				String userName=userRank.getUserName();
				String userMobile=userRank.getUserMobile();
				if(userName!=null){
					userRank.setUserName(getTackleStr(loggerInfo,userName.toString(),0,1));
				}
				if(userMobile!=null){
					userRank.setUserMobile(getTackleStr(loggerInfo,userMobile.toString(),4,3));
				}
			}
		}
		
		return resultList;
	}
	
	private String getTackleStr(String loggerInfo,String param,int num, int start) {
		if(start>=param.length()||num>=param.length()||start<1){
			return param;
		}
		logger.info(loggerInfo+"param:{param:"+param+",num:"+num+",start:"+start+"}");
		if(num>0){
			String startStr=param.substring(0, start);
			String endStr=param.substring(start+num);
			String middleStr="";
			for(int i=0;i<num;i++){
				middleStr=middleStr+"*";
			}
			
			logger.info(loggerInfo+"param:{value:"+startStr+middleStr+endStr+"}");
			return startStr+middleStr+endStr;
		}else{
			String startStr=param.substring(0, start);
			String middleStr="";
			for(int i=0;i<(param.length()-start);i++){
				middleStr=middleStr+"*";
			}
			logger.info(loggerInfo+"param:{value:"+startStr+middleStr+"}");
			return startStr+middleStr;
		}
		
		
	}

	@Override
	public int queryUserRankListCount() {
		// TODO Auto-generated method stub
		return userRankDao.queryUserRankListCount();
	}

}
